package com.loveshare.love.controller;

import java.util.List;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.loveshare.common.util.HttpClientIpUtil;
import com.loveshare.common.util.HttpRequest;
import com.loveshare.log.bean.UservisitlogInfo;
import com.loveshare.log.service.LogService;
import com.loveshare.love.bean.SimpleLoveShow;
import com.loveshare.love.service.LoveShowService;

@Controller
@RequestMapping(value="m")
public class MobileLoveController {
	@Autowired
	private LoveShowService loveShowService;
	
	@Autowired
	private LogService logService;

	/**
	 * 表白墙手机端
	 */
	@RequestMapping(value="/loveWall",method=RequestMethod.GET)
	public String loveWall(ModelMap map,HttpServletRequest request){
		String ip=HttpClientIpUtil.getIP(request);
		UservisitlogInfo ipInfo=logService.getUservisitlogInfo(ip);
		String ipInfoStr="";
		if(ipInfo!=null){
			if(ipInfo.getIpregion().equals("因为接口不稳定暂时不记录了")){
				ipInfoStr=HttpRequest.getIpRegion(ip);
			}else{
				ipInfoStr=ipInfo.getIpregion();	
			}
		}else{
			ipInfoStr=HttpRequest.getIpRegion(ip);
		}
		logService.addArticleInfo(ip,ipInfoStr,2);
		List<SimpleLoveShow>  loveShows=loveShowService.getLoveShows(1, 2000);
		map.put("loveShows", loveShows);
		return "mobile/loveWall";
	}
}
